#include "Base.h"
#include "LordProtocol.h"

void ParseRuler(const char *szRuler, int arrProperty[])
{
	if(szRuler == NULL || *szRuler == '\0')
		return;
	sscanf(szRuler,"%d,%d,%d",
		arrProperty + Property_CallScore_Time,
		arrProperty + Property_FirstOutCard_Time,
		arrProperty + Property_OutCard_Time);
}

BOOL SCDealCard::Read(CSocketStream& iStream)
{
	iStream.Read((char*)&m_nFirstCallSeat, sizeof(m_nFirstCallSeat));
	iStream.Read((char*)&m_arrHandCardData, sizeof(m_arrHandCardData));
	return TRUE;
}

BOOL SCDealCard::Write(CSocketStream& oStream) const
{
	oStream.Write((char*)&m_nFirstCallSeat, sizeof(m_nFirstCallSeat));
	oStream.Write((char*)&m_arrHandCardData, sizeof(m_arrHandCardData));
	return TRUE;
}

BOOL CSCallScore::Read(CSocketStream& iStream)
{
	iStream.Read((char*)&m_nCallScore, sizeof(m_nCallScore));
	return TRUE;
}

BOOL CSCallScore::Write(CSocketStream& oStream) const
{
	oStream.Write((char*)&m_nCallScore, sizeof(m_nCallScore));
	return TRUE;
}

BOOL SCCallScore::Read(CSocketStream& iStream)
{
	iStream.Read((char*)&m_nSeat, sizeof(m_nSeat));
	iStream.Read((char*)&m_nCallScore, sizeof(m_nCallScore));
	iStream.Read((char*)&m_nNextSeat, sizeof(m_nNextSeat));
	return TRUE;
}

BOOL SCCallScore::Write(CSocketStream& oStream) const
{
	oStream.Write((char*)&m_nSeat, sizeof(m_nSeat));
	oStream.Write((char*)&m_nCallScore, sizeof(m_nCallScore));
	oStream.Write((char*)&m_nNextSeat, sizeof(m_nNextSeat));
	return TRUE;
}

BOOL SCBottomInfo::Read(CSocketStream& iStream)
{
	iStream.Read((char*)&m_nBanker, sizeof(m_nBanker));
	iStream.Read((char*)&m_arrBottomCardData, sizeof(m_arrBottomCardData));
	return TRUE;
}

BOOL SCBottomInfo::Write(CSocketStream& oStream) const
{
	oStream.Write((char*)&m_nBanker, sizeof(m_nBanker));
	oStream.Write((char*)&m_arrBottomCardData, sizeof(m_arrBottomCardData));
	return TRUE;
}

BOOL CSOutCard::Read(CSocketStream& iStream)
{
	iStream.Read((char*)&m_nCount, sizeof(m_nCount));
	for(int i = 0; i < m_nCount; i++)
	{
        iStream.Read((char*)&m_arrOutCard[i], sizeof(int));
	}
	return TRUE;
}

BOOL CSOutCard::Write(CSocketStream& oStream) const
{
	oStream.Write((char*)&m_nCount, sizeof(m_nCount));
	for(int i = 0; i < m_nCount; i++)
	{
		oStream.Write((char*)&m_arrOutCard[i], sizeof(int));
	}
	return TRUE;
}

BOOL SCOutCard::Read(CSocketStream& iStream)
{
	iStream.Read((char*)&m_nSeat, sizeof(m_nSeat));
    iStream.Read((char*)&m_nNextSeat, sizeof(m_nNextSeat));
	iStream.Read((char*)&m_nCount, sizeof(m_nCount));
	for(int i = 0; i < m_nCount; i++)
	{
		iStream.Read((char*)&m_arrOutCard[i], sizeof(int));
	}
	return TRUE;
}

BOOL SCOutCard::Write(CSocketStream& oStream) const
{
	oStream.Write((char*)&m_nSeat, sizeof(m_nSeat));
	oStream.Write((char*)&m_nNextSeat, sizeof(m_nNextSeat));
	oStream.Write((char*)&m_nCount, sizeof(m_nCount));
	for(int i = 0; i < m_nCount; i++)
	{
		oStream.Write((char*)&m_arrOutCard[i], sizeof(int));
	}
	return TRUE;
}

BOOL SCResult::Read(CSocketStream& iStream)
{
	iStream.Read((char*)&m_nBanker, sizeof(m_nBanker));
	iStream.Read((char*)&m_nCallScore, sizeof(m_nCallScore));
	iStream.Read((char*)&m_nBombCount, sizeof(m_nBombCount));
	iStream.Read((char*)&m_bMissile, sizeof(m_bMissile));
	iStream.Read((char*)&m_bSpring, sizeof(m_bSpring));
	iStream.Read((char*)&m_arrHandCardCount, sizeof(m_arrHandCardCount));
	iStream.Read((char*)&m_arrScore, sizeof(m_arrScore));
	for(int i = 0; i < Player_Count; i++)
	{
        iStream.Read((char*)&m_arrHandCardData[i], m_arrHandCardCount[i] * sizeof(int));
	}
	return TRUE;
}

BOOL SCResult::Write(CSocketStream& oStream) const
{
	oStream.Write((char*)&m_nBanker, sizeof(m_nBanker));
	oStream.Write((char*)&m_nCallScore, sizeof(m_nCallScore));
	oStream.Write((char*)&m_nBombCount, sizeof(m_nBombCount));
	oStream.Write((char*)&m_bMissile, sizeof(m_bMissile));
	oStream.Write((char*)&m_bSpring, sizeof(m_bSpring));
	oStream.Write((char*)&m_arrHandCardCount, sizeof(m_arrHandCardCount));
	oStream.Write((char*)&m_arrScore, sizeof(m_arrScore));
	for(int i = 0; i < Player_Count; i++)
	{
		oStream.Write((char*)&m_arrHandCardData[i], m_arrHandCardCount[i] * sizeof(int));
	}
	return TRUE;
}


